/// <reference path="libs/jquery-1.4.1-vsdoc.js" />

function uForum() {
    this.DeleteTopic = function(s_topicId, element, callback) {
        $.post("/base/uForum/DeleteTopic/" + s_topicId + ".aspx", function(data) {
            var responseType = $("*", data).get(0).tagName.toLowerCase();
            if (responseType == "error") {
                alert($("error", data).text());
                callback.call(element, false);
            } else {
                if ($("value", data).text() == "1") {
                    callback.call(element, true);
                } else {
                    callback.call(element, false);
                }
            }
        });
    }

    this.DeleteComment = function(s_commentId, element, callback) {
        $.post("/base/uForum/DeleteComment/" + s_commentId + ".aspx", function(data) {
            var responseType = $("*", data).get(0).tagName.toLowerCase();
            if (responseType == "error") {
                alert($("error", data).text());
                callback.call(element, false);
            } else {
                if ($("value", data).text() == "1") {
                    callback.call(element, true);
                } else {
                    callback.call(element, false);
                }
            }
        });
    }

    this.NewTopic = function(s_forumId, s_title, s_body) {
        $.post("/base/uForum/NewTopic/" + s_forumId + ".aspx", { title: s_title, body: s_body },
			function(data) {
			    var responseType = $("*", data).get(0).tagName.toLowerCase();
			    if (responseType == "error") {
			        alert($("error", data).text());
			    } else {
			        window.location = jQuery("value", data).text();
			    }
			});
    }
    this.NewComment = function(s_topicId, s_body) {
        $.post("/base/uForum/NewComment/" + s_topicId + ".aspx", { body: s_body },
            function(data) {
                var responseType = $("*", data).get(0).tagName.toLowerCase();
                if (responseType == "error") {
                    alert($("error", data).text());
                } else {
                    window.location = jQuery("value", data).text();
                }
            });
    }

}

$(document).ready(function() {
    $(".commentsList .post .deletePost").click(function() {
        var link = $(this);
        var topicId = link.attr("rel");
        if (confirm("Are you sure you want to delete this topic?")) {
            var initForum = new uForum();
            initForum.DeleteTopic(topicId, link, function(success) {
                if (success) {
                    $(this).parents(".commentsList").hide("slow", function() {
                        alert("Topic deleted");
                    });
                }
            });
        }
        return false;
    });

    $(".commentsList .postComment .deleteComment").click(function() {
    var link = $(this);
    var commentId = link.attr("rel");
    if (confirm("Are you sure you want to delete this comment?")) {
        var initForum = new uForum();
        initForum.DeleteComment(commentId, link, function(success) {
            if (success) {
                $(this).parents(".postComment").hide("slow", function() {
                    alert("Comment deleted");
                });
            }
        });
    }
    return false;
    });

});

